// pages/community/community.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        id: 1,
        bid: 2,
        cid: 3,
        fid: 5,
        gid: 6,
        fid: 8,
        skip: 0,
        take: 1,
        takeA: 5,
        news: []
    },


    btn() {

        var that = this
        wx.request({

            url: 'https://bangkeedu.com/api/news',
            data: {

            },
            method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
            // header: {}, // 设置请求的 header
            success: function (res) {
                // success

                if (res.statusCode == 200) {
                    that.setData({
                        // 将res.data保存在listDate方便我们去循环遍历
                        news: res.data[0],


                    })
                    console.log(res)

                }
            },
            fail: function () {
                // fail
            },
            complete: function () {
                // complete
            }
        })
    },

    btntwo() {
        const { bid, skip, take } = this.data
        var that = this
        wx.request({
            url: 'https://bangkeedu.com/api/news/getNewsByCategory',
            data: {
                id: bid,
                skip: skip,
                take: take
            },
            method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
            // header: {}, // 设置请求的 header
            success: function (res) {
                // success
                if (res.statusCode == 200) {
                    that.setData({
                        // 将res.data保存在listDate方便我们去循环遍历
                        news: res.data[0],
                    })
                    // console.log(res.data.news)
                    console.log(res)
                }

            },
            fail: function () {
                // fail
            },
            complete: function () {
                // complete
            }
        })
    },
    btnthree() {
        const { cid, skip, take } = this.data
        var that = this
        wx.request({
            url: 'https://bangkeedu.com/api/news/getNewsByCategory',
            data: {
                id: cid,
                skip: skip,
                take: take
            },
            method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
            // header: {}, // 设置请求的 header
            success: function (res) {
                // success
                if (res.statusCode == 200) {
                    that.setData({
                        // 将res.data保存在listDate方便我们去循环遍历
                        news: res.data[0],


                    })
                    // console.log(res.data.news)
                    // console.log(res)
                }

            },
            fail: function () {
                // fail
            },
            complete: function () {
                // complete
            }
        })
    },
    btnfour() {
        const { fid, skip, take } = this.data
        var that = this
        wx.request({
            url: 'https://bangkeedu.com/api/news/getNewsByCategory',
            data: {
                id: fid,
                skip: skip,
                take: take
            },
            method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
            // header: {}, // 设置请求的 header
            success: function (res) {
                // success
                if (res.statusCode == 200) {
                    that.setData({
                        // 将res.data保存在listDate方便我们去循环遍历
                        news: res.data[0],


                    })
                    // console.log(res.data.news)
                    // console.log(res)
                }

            },
            fail: function () {
                // fail
            },
            complete: function () {
                // complete
            }
        })
    },
    btnfive() {
        const { gid, skip, take } = this.data
        var that = this
        wx.request({
            url: 'https://bangkeedu.com/api/news/getNewsByCategory',
            data: {
                id: gid,
                skip: skip,
                take: take
            },
            method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
            // header: {}, // 设置请求的 header
            success: function (res) {
                // success
                if (res.statusCode == 200) {
                    that.setData({
                        // 将res.data保存在listDate方便我们去循环遍历
                        news: res.data[0],


                    })
                    // console.log(res.data.news)
                    console.log(res)
                }

            },
            fail: function () {
                // fail
            },
            complete: function () {
                // complete
            }
        })
    },
    btnsix() {
        const { fid, skip, take } = this.data
        var that = this
        wx.request({
            url: 'https://bangkeedu.com/api/news/getNewsByCategory',
            data: {
                id: fid,
                skip: skip,
                take: take
            },
            method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
            // header: {}, // 设置请求的 header
            success: function (res) {
                // success
                if (res.statusCode == 200) {
                    that.setData({
                        // 将res.data保存在listDate方便我们去循环遍历
                        news: res.data[0],


                    })
                    // console.log(res.data.news)
                    console.log(res)
                }

            },
            fail: function () {
                // fail
            },
            complete: function () {
                // complete
            }
        })
    },
    goTutorDetail: function () {
        wx.navigateTo({
            url: "/pages/tutor/tutor"
        });
    },
    nav: function (e) {
        const id = e.currentTarget.dataset.bid
        console.log(id)
        wx.navigateTo({
            url: '/pages/tutor/tutor?id=' + id,
            events: {
                // 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
                acceptDataFromOpenedPage: function (id) {
                    console.log(id)
                },
                someEvent: function (id) {
                    console.log(id)
                }
            },
            success: function (res) {
                // 通过 eventChannel 向被打开页面传送数据
                res.eventChannel.emit('acceptDataFromOpenerPage', { data: 'test' })
            }
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        const { id, skip, takeA } = this.data
        var that = this
        wx.request({

            url: 'https://bangkeedu.com/api/news',
            data: {


            },
            method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
            // header: {}, // 设置请求的 header
            success: function (res) {
                // success

                if (res.statusCode == 200) {
                    that.setData({
                        // 将res.data保存在listDate方便我们去循环遍历
                        news: res.data[0],


                    })
                    console.log(res)

                }
            },
            fail: function () {
                // fail
            },
            complete: function () {
                // complete
            }
        })

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})